<?php


namespace Tbf\Component\Exception;


class ExceptionFunction {
    static function exceptionToArray(\Exception $e){
        return self::exceptionToArrayRecursion($e,10);
    }
    protected static function exceptionToArrayRecursion(\Exception $e,$level){
        if ($level<=0){
            return null;
        }
        $previous = $e->getPrevious();
        if ($previous!==null){
            $previous = self::exceptionToArrayRecursion($previous,$level-1);
        }
        return array(
            'message'=>$e->getMessage(),
            'file'=>$e->getFile(),
            'line'=>$e->getLine(),
            'trace'=>$e->getTraceAsString(),
            'code'=>$e->getCode(),
            'previous'=>$previous
        );

    }
}